package com.ruoyi.hr.controller.hr.welfare.welfareregion;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.hr.domain.welfare.welfareregion.WelfareRound;
import com.ruoyi.hr.domain.welfare.welfareregion.WelfareTypeColumns;
import com.ruoyi.hr.service.welfare.welfareRegion.WelfareRegionParameterConfigService;
import com.ruoyi.hr.service.welfare.welfareRegion.WelfareTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * @author zeo
 * @explain 福利地区参数配置
 * @date 2019/12/20 13:52
 */
@Controller
@RequestMapping("/welfare/region/welfareRegionParameterConfig")
public class WelfareRegionParameterConfigController extends BaseController {
    @Autowired
    private WelfareTypeService welfareTypeService;

    @Autowired
    private WelfareRegionParameterConfigService welfareRegionParameterConfigService;

    private String prefix = "hr/welfare/welfareregion/welfareRegionParameterConfig";

    /**
     * 福利地区参数配置跳转
     * @return
     */
    @GetMapping()
    public String welfareRegionParameterConfig() {
        return prefix + "/welfareRegionParameterConfig";
    }

    /**
     * 获取福利类型动态加载字段列表
     *
     * @return
     */
    @RequestMapping("getColumn")
    @ResponseBody
    public List<WelfareTypeColumns> getColumn() {
        return welfareTypeService.findAll();
    }

    /**
     * 获取数据
     *
     * @return
     */
    @RequestMapping("list")
    @ResponseBody
    public TableDataInfo list() {
        List<Map<String, Object>> list = welfareRegionParameterConfigService.findData();
        //有没有key，若没有，加一个，值为空
        List<WelfareTypeColumns> welfareTypeColumns = welfareTypeService.findAll();
        for (Map<String, Object> map : list) {
            for (WelfareTypeColumns welfareTypeColumns1 : welfareTypeColumns) {
                if (!map.containsKey(welfareTypeColumns1.getField())) {
                    map.put(welfareTypeColumns1.getField(), 0);
                }
            }
        }
        return getDataTable1(list, list.size());
    }

    /**
     * 修改福利地区参数配置
     *
     * @param cityId           区域ID
     * @param benefitTypeAndXl 福利类型和类型小类
     * @return
     */
    @RequestMapping("update")
    @ResponseBody
    public int update(String cityId, String benefitTypeAndXl, String updVal) {
        return welfareRegionParameterConfigService.update(cityId, benefitTypeAndXl, updVal);
    }

    /**
     * 获取进位方式
     */
    @ResponseBody
    @RequestMapping("findWelfareRound")
    public List<WelfareRound> findWelfareRound() {
        return welfareRegionParameterConfigService.findWelfareRound();
    }
}

